//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __CBASICDIRECTORY_H__
#define __CBASICDIRECTORY_H__

#ifndef __UUNM_elasys_DEFINED__
#define __UUNM_elasys_DEFINED__
#ifdef __cplusplus
static const wchar_t * const c_pelasysUunm = \
    L"elastos.dll";
#else

#define c_pelasysUunm L"elastos.dll"
#endif
// __cplusplus
#endif // __UUNM_elasys_DEFINED__

#ifndef __ECLSID_CBasicDirectory_DEFINED__
#define __ECLSID_CBasicDirectory_DEFINED__
static const ClassID ECLSID_CBasicDirectory = {
    {0xAEAE162B,0x188C,0x3F59,{0x50,0xBC,0x20,0x61,0x83,0x87,0x0D,0x00}},
    (wchar_t *)c_pelasysUunm };
#endif // __CLSID_CBasicDirectory_DEFINED__

class CBasicDirectory : public IBasicDirectory, IFileMonitor
{
public:
    CARAPI_(PInterface) Probe(
         /* [in]  */ REIID riid);

    CARAPI_(UInt32) AddRef(void);

    CARAPI_(UInt32) Release(void);

    CARAPI Aggregate(
        /* [in] */ AggrType aggrType,
        /* [in] */ PInterface pObject);

    CARAPI GetDomain(
         /* [out] */ PInterface *ppObj);

    CARAPI Sync();

    CARAPI GetType(
        /* [out] */ FileType * pType);

    CARAPI GetAccessTime(
        /* [out] */ INT * pTime);

    CARAPI SetAccessTime(
        /* [in] */ INT time);

    CARAPI GetModificationTime(
        /* [out] */ INT * pTime);

    CARAPI SetModificationTime(
        /* [in] */ INT time);

    CARAPI GetCreateTime(
        /* [out] */ INT * pTime);

    CARAPI CheckAccessMode(
        /* [in] */ FileAccessMode mode);

    CARAPI GetAccessMode(
        /* [out] */ FileAccessMode * pMode);

    CARAPI SetAccessMode(
        /* [in] */ FileAccessMode mode);

    CARAPI GetShareMode(
        /* [out] */ FileShareMode *pMode);

    CARAPI SetShareMode(
        /* [in] */ FileShareMode mode);

    CARAPI Lookup(
        /* [in] */ WString name,
        /* [out] */ IBasicFile ** piBasicFile);

    CARAPI CreateFile(
        /* [in] */ WString name,
        /* [in] */ FileAccessMode cmode,
        /* [in] */ Boolean bExclusive,
        /* [out] */ IBasicFile ** piBasicFile);

    CARAPI DeleteFile(
        /* [in] */ WString name);

    CARAPI Rename(
        /* [in] */ WString oldName,
        /* [in] */ IBasicDirectory * pNewDir,
        /* [in] */ WString newName);

    CARAPI CreateDirectory(
        /* [in] */ WString name,
        /* [in] */ FileAccessMode mode);

    CARAPI DeleteDirectory(
        /* [in] */ WString name);

    CARAPI GetDirEntries(
        /* [out] */ IWStringEnumerator ** piEntryNameEnumerator);

    CARAPI CombineName(
         /* [in] */  WString name,
         /* [out] */ wchar_t *fullname);

    CARAPI AddFileMonitor(
        /* [out] */ IEvent **pEvent);

    CARAPI RemoveFileMonitor(
        /* [in] */ IEvent *pEvent);

    CBasicDirectory();
    CBasicDirectory(WString esDir);
    virtual ~CBasicDirectory();

private:
    // TODO: Add you private member variables here
    wchar_t* m_wstrCurDir;

    FileAccessMode m_eFMode;
    INT m_iCreateTime;
    INT m_iAccessTime;
    INT m_iModificationTime;

    CARAPI GetNameStat(
         /* [in] */  wchar_t *wcsName,
         /* [out] */ BOOL *bIsExist,
         /* [out] */ BOOL *bIsDir);

    HANDLE m_DirHandle;
    Interlocked     m_cRef;
    RTL_CRITICAL_SECTION m_FileLock;
};

#endif // __CBASICDIRECTORY_H__
